#include "TransformList.h"

TransformList::TransformList(void)
{
}

TransformList::~TransformList(void)
{
	m_Transforms.clear();
}

Transform* TransformList::AddTranslationTransform(float x, float y, float z)
{
	TRSTransform*  t = new TRSTransform();
	t->SetTranslation(x,y,z);
	m_Transforms.push_back(t);
	return t;
}
	
Transform* TransformList::AddRotationTransform(float rotx, float roty, float rotz)
{
	TRSTransform* t = new TRSTransform();
	t->SetRotation(rotx,roty,rotz);
	m_Transforms.push_back(t);
	return t;
}
	
Transform* TransformList::AddQuaternionTransform(float x, float y, float z, float angle)
{
	QuaternionTransform* t = new QuaternionTransform();
	t->SetAxisAngleRotation(x,y,z,angle);
	m_Transforms.push_back(t);
	return t;
}

bool TransformList::IsChanged() const
{
	vector<Transform*>::const_iterator it;
	for ( it= m_Transforms.begin(); it != m_Transforms.end(); it++)
	{
		Transform* t = *it;
		if ( t->IsChanged() )
			return true;
	}
	return false;
}

void TransformList::RecalculateMatrix() const
{
	m_CompiledMatrix.SetAsIdentity();
	vector<Transform*>::const_iterator it;
	for ( it= m_Transforms.begin(); it != m_Transforms.end(); it++)
	{
		Transform* t = *it;
		m_CompiledMatrix.Multiply(&m_CompiledMatrix,&(t->GetCompiledMatrix()));
	}
}

void TransformList::ResetTransformParameters()
{
	vector<Transform*>::iterator it;
	for ( it = m_Transforms.begin(); it != m_Transforms.end(); it++)
	{
		delete (*it);
	}
	m_Transforms.clear();
	SetChanged(true);
}